﻿using System;
using Assets.Scripts.UI.View.Pause;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityStandardAssets.CinematicEffects;
using UnityStandardAssets.ImageEffects;

// Token: 0x02000226 RID: 550
public class CameraEffectsSettings : MonoBehaviour
{
	// Token: 0x06000B72 RID: 2930 RVA: 0x000600BC File Offset: 0x0005E2BC
	private void Awake()
	{
		this.qualityLevel = QualitySettings.GetQualityLevel();
		Application.targetFrameRate = GlobalPreferences.Fps.value;
		VideoSettingsView.UpdateAntiAliasingMode(GlobalPreferences.AntiAlias.value, false);
		VideoSettingsView.UpdateVsyncMode(GlobalPreferences.Vsync.value, false);
		QualitySettings.lodBias = GlobalPreferences.ViewDistance.value;
		PerformanceTuner.SetRenderEngine(this.qualityLevel);
		this.CurrentBehaviour = base.GetComponent<PostProcessingBehaviour>();
		if (this.CurrentBehaviour != null && this.CurrentBehaviour.profile != null)
		{
			this.CurrentProfile = UnityEngine.Object.Instantiate<PostProcessingProfile>(this.CurrentBehaviour.profile);
			this.CurrentBehaviour.profile = this.CurrentProfile;
		}
		this.nearFarCameraTreshold = GlobalPreferences.ClipDistance.value;
		this.EnableShadows(GlobalPreferences.Shadows.value);
		this.SetShadowDistance(GlobalPreferences.ShadowDistance.value);
		RenderSettings.fog = false;
		this.globalFog = base.GetComponent<GlobalFog>();
		RenderSettings.fogMode = FogMode.Linear;
		this.depthOfField = base.GetComponent<UnityStandardAssets.CinematicEffects.DepthOfField>();
		if (this.depthOfField)
		{
			this.depthOfField.enabled = GlobalPreferences.DepthOfField.value;
			UnityStandardAssets.CinematicEffects.DepthOfField.QualityPreset filteringQuality;
			switch (this.qualityLevel)
			{
			case 0:
			case 1:
				filteringQuality = UnityStandardAssets.CinematicEffects.DepthOfField.QualityPreset.Low;
				goto IL_166;
			case 2:
			case 3:
				filteringQuality = UnityStandardAssets.CinematicEffects.DepthOfField.QualityPreset.Medium;
				goto IL_166;
			}
			filteringQuality = UnityStandardAssets.CinematicEffects.DepthOfField.QualityPreset.High;
			IL_166:
			UnityStandardAssets.CinematicEffects.DepthOfField.GlobalSettings settings = this.depthOfField.settings;
			settings.filteringQuality = filteringQuality;
			this.depthOfField.settings = settings;
		}
		else
		{
			Debug.LogWarning("No reference for Depth of Field");
		}
		this.SetAmbientOcclusion(GlobalPreferences.AmbientOcclusionValue.value);
		this.SetLensAberration(GlobalPreferences.ChromaticAberration.value);
		this.SetBloom(GlobalPreferences.Bloom.value);
		this.SetBloom(GlobalPreferences.BloomValue.value);
		this.SetMotionBlur(GlobalPreferences.MotionBlur.value);
		this.mainCamera = Camera.main;
		this.parentCamera = this.mainCamera.transform.parent;
		this.farCamera = this.mainCamera.transform.GetChild(0).GetComponent<Camera>();
		this.initialized = true;
	}

	// Token: 0x06000B73 RID: 2931 RVA: 0x000602F2 File Offset: 0x0005E4F2
	public void LateUpdate()
	{
		this.UpdateEffectsRealtime();
	}

	// Token: 0x06000B74 RID: 2932 RVA: 0x000602FC File Offset: 0x0005E4FC
	public void UpdateEffectsRealtime()
	{
		float y = this.parentCamera.localScale.y;
		this.mainCamera.nearClipPlane = this.defaultNearPlane * y;
		if (this.nearFarCameraTreshold < 1f)
		{
			this.nearFarCameraTreshold = 1f;
		}
		this.mainCamera.farClipPlane = this.mainCamera.nearClipPlane * (this.farPlaneRatio * this.nearFarCameraTreshold);
		RenderSettings.fogEndDistance = this.mainCamera.farClipPlane / this.fogPercentage;
		RenderSettings.fogColor = this.fogColor;
		float num = this.mainCamera.farClipPlane - 10f;
		if (num < 0.1f)
		{
			num = 0.1f;
		}
		this.farCamera.nearClipPlane = num;
		if (this.farCamera.nearClipPlane > this.farCamera.farClipPlane)
		{
			this.farCamera.farClipPlane = this.farCamera.nearClipPlane + 10f;
		}
		QualitySettings.shadowDistance = CameraEffectsSettings.shadowDistance * y;
		QualitySettings.shadowNearPlaneOffset = CameraEffectsSettings.shadowDistance * 0.01f * y;
		this.AdjustDoF(y);
	}

	// Token: 0x06000B75 RID: 2933 RVA: 0x0006041C File Offset: 0x0005E61C
	public void AdjustDoF(float scale)
	{
		if (this.depthOfField != null)
		{
			if (scale < ResizeCharacter.minSize)
			{
				scale = ResizeCharacter.minSize;
			}
			float num = this.maxDOFBlurRadius / Mathf.Log10(scale * 1000f);
			if (num > this.maxDOFBlurRadius)
			{
				num = this.maxDOFBlurRadius;
			}
			this.depthOfField.focus.farPlane = this.mainCamera.farClipPlane * 0.5f;
			this.depthOfField.focus.farFalloff = this.mainCamera.farClipPlane;
			this.depthOfField.focus.farBlurRadius = num;
		}
	}

	// Token: 0x06000B76 RID: 2934 RVA: 0x000604C0 File Offset: 0x0005E6C0
	public void SetLensAberration(bool value)
	{
		if (this.CurrentProfile)
		{
			this.CurrentProfile.chromaticAberration.enabled = value;
		}
	}

	// Token: 0x06000B77 RID: 2935 RVA: 0x000604E4 File Offset: 0x0005E6E4
	public void SetLensAberration(float value)
	{
		if (!this.CurrentProfile)
		{
			return;
		}
		ChromaticAberrationModel.Settings settings = this.CurrentProfile.chromaticAberration.settings;
		settings.intensity = value;
		this.CurrentProfile.chromaticAberration.settings = settings;
	}

	// Token: 0x06000B78 RID: 2936 RVA: 0x0006052C File Offset: 0x0005E72C
	public float GetLensAberration()
	{
		return GlobalPreferences.ChromaticAberration.value;
	}

	// Token: 0x06000B79 RID: 2937 RVA: 0x00060538 File Offset: 0x0005E738
	public void SetBloom(bool value)
	{
		if (this.CurrentProfile)
		{
			this.CurrentProfile.bloom.enabled = value;
		}
	}

	// Token: 0x06000B7A RID: 2938 RVA: 0x0006055C File Offset: 0x0005E75C
	public void SetBloom(float value)
	{
		if (!this.CurrentProfile)
		{
			return;
		}
		BloomModel.Settings settings = this.CurrentProfile.bloom.settings;
		settings.bloom.intensity = value;
		this.CurrentProfile.bloom.settings = settings;
	}

	// Token: 0x06000B7B RID: 2939 RVA: 0x000605A9 File Offset: 0x0005E7A9
	public void SetColorGain(float value, bool write = false)
	{
		this.colorGrading.basics.gain = value;
		this.colorGrading.enabled = true;
	}

	// Token: 0x06000B7C RID: 2940 RVA: 0x000605C8 File Offset: 0x0005E7C8
	public float GetColorGain()
	{
		return this.colorGrading.basics.gain;
	}

	// Token: 0x06000B7D RID: 2941 RVA: 0x000605DA File Offset: 0x0005E7DA
	public void SetColorValue(float value, bool write = false)
	{
		this.colorGrading.basics.value = value;
		this.colorGrading.enabled = true;
	}

	// Token: 0x06000B7E RID: 2942 RVA: 0x000605F9 File Offset: 0x0005E7F9
	public float GetColorValue()
	{
		return this.colorGrading.basics.value;
	}

	// Token: 0x06000B7F RID: 2943 RVA: 0x0006060B File Offset: 0x0005E80B
	public void SetAmbientOcclusion(bool value)
	{
		if (this.CurrentProfile)
		{
			this.CurrentProfile.ambientOcclusion.enabled = value;
		}
	}

	// Token: 0x06000B80 RID: 2944 RVA: 0x00060630 File Offset: 0x0005E830
	public void SetAmbientOcclusion(float value)
	{
		if (!this.CurrentProfile)
		{
			return;
		}
		AmbientOcclusionModel.Settings settings = this.CurrentProfile.ambientOcclusion.settings;
		settings.radius = value;
		this.CurrentProfile.ambientOcclusion.settings = settings;
		this.UpdateDepth();
	}

	// Token: 0x06000B81 RID: 2945 RVA: 0x0006067E File Offset: 0x0005E87E
	public float GetAmbientOcclusion()
	{
		return GlobalPreferences.AmbientOcclusionValue.value;
	}

	// Token: 0x06000B82 RID: 2946 RVA: 0x0006068A File Offset: 0x0005E88A
	public float GetShadowDistance()
	{
		return CameraEffectsSettings.shadowDistance;
	}

	// Token: 0x06000B83 RID: 2947 RVA: 0x00060691 File Offset: 0x0005E891
	public void SetShadowDistance(float distance)
	{
		CameraEffectsSettings.shadowDistance = distance;
	}

	// Token: 0x06000B84 RID: 2948 RVA: 0x00060699 File Offset: 0x0005E899
	public void SwitchShadows()
	{
		this.EnableShadows(!this.GetShadowsValue());
	}

	// Token: 0x06000B85 RID: 2949 RVA: 0x000606AA File Offset: 0x0005E8AA
	public bool GetShadowsValue()
	{
		return GlobalPreferences.Shadows.value;
	}

	// Token: 0x06000B86 RID: 2950 RVA: 0x000606B6 File Offset: 0x0005E8B6
	public void EnableShadows(bool value)
	{
		if (value)
		{
			if (QualitySettings.GetQualityLevel() < 3)
			{
				QualitySettings.shadows = ShadowQuality.HardOnly;
			}
			else
			{
				QualitySettings.shadows = ShadowQuality.All;
			}
		}
		else
		{
			QualitySettings.shadows = ShadowQuality.Disable;
		}
	}

	// Token: 0x06000B87 RID: 2951 RVA: 0x000606E5 File Offset: 0x0005E8E5
	public bool GetDepthOfFieldValue()
	{
		return this.depthOfField != null && this.depthOfField.enabled;
	}

	// Token: 0x06000B88 RID: 2952 RVA: 0x00060706 File Offset: 0x0005E906
	public bool GetAmbientOcclusionValue()
	{
		return this.CurrentProfile && this.CurrentProfile.ambientOcclusion.enabled;
	}

	// Token: 0x06000B89 RID: 2953 RVA: 0x0006072C File Offset: 0x0005E92C
	public void UpdateDepth()
	{
		if (!this.initialized)
		{
			return;
		}
		if (UnityEngine.Object.FindObjectOfType<AQUAS_Reflection>() != null)
		{
			return;
		}
		DepthTextureMode depthTextureMode = DepthTextureMode.DepthNormals;
		if (!this.GetAmbientOcclusionValue())
		{
			if (!this.GetDepthOfFieldValue())
			{
				depthTextureMode = DepthTextureMode.None;
			}
			else
			{
				depthTextureMode = DepthTextureMode.Depth;
			}
		}
		this.mainCamera.depthTextureMode = depthTextureMode;
	}

	// Token: 0x06000B8A RID: 2954 RVA: 0x00060783 File Offset: 0x0005E983
	public float GetHaze()
	{
		if (this.globalFog == null || !this.globalFog.enabled)
		{
			return 0.01f;
		}
		return this.fogPercentage;
	}

	// Token: 0x06000B8B RID: 2955 RVA: 0x000607B2 File Offset: 0x0005E9B2
	public void SetHaze(bool val)
	{
		if (this.globalFog)
		{
			this.globalFog.enabled = val;
		}
	}

	// Token: 0x06000B8C RID: 2956 RVA: 0x000607D0 File Offset: 0x0005E9D0
	public void SetHaze(float val)
	{
		if (val < 0.01f)
		{
			return;
		}
		if (this.globalFog)
		{
			this.fogPercentage = val;
		}
	}

	// Token: 0x06000B8D RID: 2957 RVA: 0x000607F5 File Offset: 0x0005E9F5
	public void SetLongFarPlane(bool value)
	{
		this.longFarPlane = value;
	}

	// Token: 0x06000B8E RID: 2958 RVA: 0x000607FE File Offset: 0x0005E9FE
	public bool GetLongFarPlane()
	{
		return this.longFarPlane;
	}

	// Token: 0x06000B8F RID: 2959 RVA: 0x00060806 File Offset: 0x0005EA06
	public void SetMotionBlur(bool value)
	{
		if (this.CurrentProfile)
		{
			this.CurrentProfile.motionBlur.enabled = value;
		}
	}

	// Token: 0x06000B90 RID: 2960 RVA: 0x00060829 File Offset: 0x0005EA29
	public bool GetMotionBlur()
	{
		return GlobalPreferences.MotionBlur.value;
	}

	// Token: 0x040010B4 RID: 4276
	public static float shadowDistance = 200f;

	// Token: 0x040010B5 RID: 4277
	public float defaultNearPlane = 0.1f;

	// Token: 0x040010B6 RID: 4278
	private float farPlaneRatio = 20000f;

	// Token: 0x040010B7 RID: 4279
	public float nearFarCameraTreshold = 1f;

	// Token: 0x040010B8 RID: 4280
	public bool longFarPlane;

	// Token: 0x040010B9 RID: 4281
	[Range(0.01f, 1f)]
	public float fogPercentage = 0.3f;

	// Token: 0x040010BA RID: 4282
	public Color fogColor = Color.white;

	// Token: 0x040010BB RID: 4283
	private GlobalFog globalFog;

	// Token: 0x040010BC RID: 4284
	public PostProcessingBehaviour CurrentBehaviour;

	// Token: 0x040010BD RID: 4285
	public PostProcessingProfile CurrentProfile;

	// Token: 0x040010BE RID: 4286
	public UnityStandardAssets.CinematicEffects.DepthOfField depthOfField;

	// Token: 0x040010BF RID: 4287
	private float maxDOFBlurRadius = 30f;

	// Token: 0x040010C0 RID: 4288
	private TonemappingColorGrading.ColorGradingSettings colorGrading;

	// Token: 0x040010C1 RID: 4289
	private Camera mainCamera;

	// Token: 0x040010C2 RID: 4290
	private Transform parentCamera;

	// Token: 0x040010C3 RID: 4291
	private Camera farCamera;

	// Token: 0x040010C4 RID: 4292
	private bool initialized;

	// Token: 0x040010C5 RID: 4293
	private int qualityLevel;
}
